package com.example.demo.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.order.service.IOFeeStandardService;
import com.example.demo.order.entity.OFeeStandard;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 费用规格表; 前端控制器
 * </p>
 *
 * @author tao
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/oFeeStandard")
    public class OFeeStandardController {

    @Autowired
    private IOFeeStandardService oFeeStandardService;

    /**
    * 获取相关列表
     * @param current
     * @param size
     * @return
    */
    @GetMapping("/getOFeeStandardList")
    public Result<?> getOFeeStandardList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                            @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                            OFeeStandard oFeeStandard){

        Page<OFeeStandard> page = new Page<>(current,size);
        QueryWrapper<OFeeStandard> queryWrapper=new QueryWrapper<>(oFeeStandard);
        queryWrapper.orderByDesc("id");
        return Result.ok(oFeeStandardService.page(page,queryWrapper));
    }

    /**
         * 根据ID查询信息
         */
    @GetMapping("/getOFeeStandardById")
    public Result<?> getOFeeStandardById(Integer id){
        return Result.ok(oFeeStandardService.getById(id));
    }

    /**
         * 修改
         */
    @PutMapping("/updateOFeeStandard")
    @Transactional
    public Result<?> updateOFeeStandard(@RequestBody OFeeStandard oFeeStandard){
        return Result.ok(oFeeStandardService.updateById(oFeeStandard));
    }

    /**
         * 新增
         */
    @PostMapping("/addOFeeStandard")
    public Result<?> addOFeeStandard(@RequestBody OFeeStandard oFeeStandard){
        return Result.ok(oFeeStandardService.save(oFeeStandard));
    }

    /**
         * 删除
         */
    @DeleteMapping("/deleteOFeeStandardById")
    @Transactional
    public Result<?> deleteOFeeStandard(Integer id){
        return Result.ok(oFeeStandardService.removeById(id));
    }

    /**
     * 根据用户ID查询信息
     */
    @GetMapping("/getOFeeStandardByUserId")
    public Result<?> getOFeeStandardByUserId(Integer id){
        QueryWrapper<OFeeStandard> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        return Result.ok(oFeeStandardService.getOne(queryWrapper));
    }

}

